//includes
#include "framework.h"

void runRound (int roundNumber, Graph *g)
{
    Node *node;
    NodeList *nodes;

    Packet *packet;
    Node *toNode;

    if (g == NULL)
        return;

    nodes = g->nodes;
    if (nodes == NULL)
        return;

    for (node = nodes->head; node != NULL; node = node->next)
    {
        while ((packet = popPacket(node->outbox)) != NULL)
        {
            toNode = findNode(g, packet->to);

            if (toNode != NULL)
                pushPacket (toNode->inbox, packet);
        }
    }

    for (node = nodes->head; node != NULL; node = node->next)
    {
        g->nodeComputation(roundNumber, node);
    }
}

void startRounds(Graph *g)
{
    runRound (1, g);
    runRound (2, g);
}
